<template>
    <select ref="selectElement">
        <slot></slot>
    </select>
</template>
<script>
    export default {
        name: "nc-select",
        //外部传入参数
        props: {
            currentSelectValue: {
                type: String,
                default: ''
            }
        },
        /*
         * 自身数据,一定要一个function
         */
        data() {
            return {}
        },
        computed: {},
        watch: {
            currentSelectValue(value){
                this.refreshCurrentSelect(value , false )
            }
        },
        directives: {},
        created() {

        },
        mounted() {
            var self = this ,
                el = $(this.$refs.selectElement)
            el.chosen({
                disable_search: true,
                width:'150px'
            }).on('change', function () {
                self.$emit('change',{value : el.val() , name : el.find(':selected').html()})
            })
            this.refreshCurrentSelect(this.currentSelectValue)
        },
        methods: {
            refreshCurrentSelect (value){
                $(this.$refs.selectElement).val(value).trigger("chosen:updated")
            }
        }
    }
</script>